package agh.tk.markuptranslation;
public class Link extends AbstractComponent
{
	/*
	 * leftChild - adres linkowanej strony
	 * rightChild - ewentualny tekst wyswietlanego linka(niekonieczny)
	 */
	public Link(IComponent leftChild, IComponent rightChild) 
	{
		super(leftChild, rightChild);
	}
	@Override
	public String toDokuWiki()
	{
		StringBuilder stringBuilder  = new StringBuilder("[[") ;
		stringBuilder.append(toDokuWiki("|")) ;
		stringBuilder.append("]]") ;
		return stringBuilder.toString() ;
	}
	
	@Override
	public String toMediaWiki() {
		StringBuilder stringBuilder  = new StringBuilder("[[");
		stringBuilder.append(toMediaWiki("|"));
		stringBuilder.append("]]");
		return stringBuilder.toString();
	}
	
	@Override
	public String toHTML() {
		StringBuilder stringBuilder  = new StringBuilder("<a href=\"");
		stringBuilder.append(leftChild.toHTML());
		stringBuilder.append("\">");
		if(rightChild == null)
			stringBuilder.append(leftChild.toHTML());
		else
			stringBuilder.append(rightChild.toHTML());
		stringBuilder.append("</a>");
		return stringBuilder.toString() ;
	}
	
	@Override 
	public String toTxt2tags()
	{
		if(rightChild == null)
			return leftChild.toTxt2tags() ;
		StringBuilder stringBuilder = new StringBuilder() ;
		stringBuilder.append('[') ;
		stringBuilder.append(rightChild.toTxt2tags()) ;
		stringBuilder.append(" ") ;
		stringBuilder.append(leftChild.toTxt2tags()) ;
		stringBuilder.append(']') ;
		return stringBuilder.toString() ;
	}
}
